﻿using AutoMapper;
using BlogApi.Models;
using BlogApi.ModelsDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlogApi.Profiles
{
    public class ArticleProfile:Profile
    {
        public ArticleProfile()
        {
            CreateMap<ArticleAddDto, Article>().ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.ArticleTitle))
                .ForMember(dest => dest.Content, opt => opt.MapFrom(src => src.ArticleMarkDown));
            CreateMap<Article, ArticleDto>().ForMember(dest => dest.ArticleId, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.AuthorId, opt => opt.MapFrom(src => src.UserId))
                .ForMember(dest => dest.GoodCount, opt => opt.MapFrom(src => src.GoodNumber))
                .ForMember(dest => dest.BrowseCount, opt => opt.MapFrom(src => src.BrowseNumber))
                .ForMember(dest => dest.CommentCount, opt => opt.MapFrom(src => src.CommentNumber))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime.ToString("yyyy-MM-dd")))
                .ForMember(dest => dest.ArticleMarkDownContent, opt => opt.MapFrom(src => src.Content));
        }
    }
}
